local skel = fk.CreateSkill {
  name = "efengqi__guixin",
}

Fk:loadTranslationTable{
  ["efengqi__guixin"] = "归心",
  [":efengqi__guixin"] = "你受到伤害后，可以获得攻击范围内有你的角色各一张牌。你可以先翻面，改为没有你。",

  ["efengqi__guixin1"] = "归心：获得攻击范围内有你的角色各一张牌",
  ["efengqi__guixin2"] = "归心：翻面，获得攻击范围内没有你的角色各一张牌",

  ["$efengqi__guixin1"] = "周公吐哺，天下归心！",
  ["$efengqi__guixin2"] = "山不厌高，海不厌深！",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  on_cost = function(self, event, target, player, data)
    local choice = player.room:askToChoice(player, { choices = {"efengqi__guixin1", "efengqi__guixin2", "Cancel"}, skill_name = self.name})
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local turnOver = event:getCostData(self).choice == "efengqi__guixin2"
    local targets = table.filter(room:getAlivePlayers(), function (p)
      return p:inMyAttackRange(player)
    end)
    if turnOver then
      targets = table.filter(room:getAlivePlayers(), function (p)
        return not p:inMyAttackRange(player)
      end)
      player:turnOver()
      if player.dead then return end
    end
    room:doIndicate(player, targets)
    for _, p in ipairs(targets) do
      if player.dead then return end
      if p == player then
        if #player:getCardIds("e") > 0 then
          local id = room:askToChooseCard(player, { target = player, flag = "e", skill_name = self.name})
          room:obtainCard(player, id, true, fk.ReasonPrey)
        end
      elseif not p:isNude() then
        local id = room:askToChooseCard(player, { target = p, flag = "he", skill_name = self.name})
        room:obtainCard(player, id, false, fk.ReasonPrey)
      end
    end
  end,
})

return skel
